/*
 * EventType.java
 *
 * Created on December 5, 2007, 1:57 PM
 *
 *  Copyright (C) 2010 Tal Eisenberg
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package tal.drivechain.variable.types;

import tal.drivechain.chain.ChainNode;
import tal.drivechain.matchers.ValueMatcher;
import tal.drivechain.variable.expressions.CustomExpression;

/**
 * A DataType class for using event variables.
 * Name: "event"
 * Value object: Boolean
 * Value range: Always null
 * Type code: 11
 * Syntax: <varname>:event: (the extra colons are annoying).
 * Can cast from any other value.
 * Variables of this data type are used when a message is sent with no other information except a 
 * name. For example when the main chain is opened the chain will send a global message to all its modules that contains
 * a variable named "init" of type event.
 *
 * @author Tal Eisenberg
 */
public class EventType extends DataType {
    
    /** Creates a new instance of EventType */
    public EventType() {
        super("event", Object.class, 11);
    }

    public Object parseValue(String value) throws IllegalArgumentException {
        if (value!=null && value.trim().length()!=0) throw new IllegalArgumentException("Event variables can't store a value (" + value + ")");
        return null;
    }

    @Override
    public Object cast(Object value) throws IllegalArgumentException {
        return null;
    }
    
    @Override
    public String toString(Object value, ChainNode context) {
        return "";
    }

    @Override
    public CustomExpression createExpression(String value) throws IllegalArgumentException {
        throw new IllegalArgumentException("event variables have null values, and can't be assigned to an expression.");
    }

    @Override
    public ValueMatcher createValueMatcher() throws IllegalArgumentException {
        throw new IllegalArgumentException("Value matchers are not supported for event variables.");
    }
}
